1
2
3
4
5
6
7 package uk.ac.roe.antigen.dialogs;
8
9 import java.awt.Color;
10 import java.awt.Font;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
13 import java.awt.event.WindowAdapter;
14 import java.awt.event.WindowEvent;
15 import java.util.logging.Level;
16 import java.util.logging.Logger;
17
18 import javax.swing.ImageIcon;
19 import javax.swing.JFrame;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22 import javax.swing.Timer;
23
24 import uk.ac.roe.antigen.utils.Config;
25
26 /***
27 * A very quick and dirty splashscreen class
28 * @author Jon Tayler johndavidtaylor@users.sourceforge.net
29 *
30 */
31 public class SplashScreen extends JFrame {
32 /***
33 * Logger for this class
34 */
35 private static final Logger logger = Logger.getLogger(SplashScreen.class.getName());
36
37 public SplashScreen() {
38 initGUI();
39 }
40
41
42 /***
43 *
44 */
45 private void initGUI() {
46 setUndecorated(true);
47
48 JPanel main = new JPanel();
49 JLabel graphic = new JLabel();
50 graphic.setOpaque(false);
51 main.setOpaque(true);
52 String logoPath = Config.getProperty("antigen.splash.logo");
53 String logoText = Config.getProperty("antigen.splash.text","Antigen");
54 graphic.setText(logoText);
55
56 String colour = Config.getProperty("antigen.splash.colour","000000");
57 logger.fine("Setting foreground colour to "+colour);
58 graphic.setForeground(new Color(Integer.parseInt(colour,16)));
59 String backgroundColour = Config.getProperty("antigen.splash.background","fffff");
60 logger.fine("Setting background colour to "+backgroundColour);
61 main.setBackground(new Color(Integer.parseInt(backgroundColour,16)));
62 graphic.setFont(new Font(Config.getProperty("antigen.splash.font","Eurostile"),
63 Integer.parseInt(Config.getProperty("antigen.splash.style","1")),
64 Integer.parseInt(Config.getProperty("antigen.splash.size","36"))));
65
66
67 if (logoPath !=null) {
68 graphic.setIcon(new ImageIcon(getClass().getClassLoader()
69 .getResource(logoPath)));
70 }
71
72 getContentPane().add(main);
73 main.add(graphic);
74 pack();
75 new FrameCenterer(this).center();
76
77 addWindowListener(new WindowAdapter () {
78 public void windowDeactivated(WindowEvent e) {
79 toFront();
80 }
81 });
82 }
83
84
85
86 /***
87 * Show the splash screen for a set number of millis
88 * @param millis time it's up
89 */
90 public void show(int millis) {
91 final Timer timer = new Timer(millis, new ActionListener() {
92
93 public void actionPerformed(ActionEvent arg0) {
94 logger.fine("Closing Splashscreen");
95 dispose();
96 }
97
98 });
99 super.show();
100 timer.setRepeats(false);
101 timer.start();
102 }
103
104 public void show() {
105 String delayString = Config.getProperty("antigen.splash.delay");
106 if (delayString==null) {
107
108 super.show();
109 } else {
110 show(Integer.parseInt(delayString));
111 }
112 }
113
114 public static void main(String[] args) throws InterruptedException {
115 Config.setProperty("antigen.splash.logo","local-img/world.jpg");
116 final SplashScreen test = new SplashScreen();
117
118
119
120
121
122
123
124 test.show(2000);
125
126
127 }
128 }